<template>
    <el-breadcrumb separator="/" style="margin-top: 10px;">
        <el-breadcrumb-item @click="back()">返回上一级</el-breadcrumb-item>
        <el-breadcrumb-item @click="all()">
            <span style="cursor: pointer;"> 全部文件</span>
        </el-breadcrumb-item>
        <el-breadcrumb-item @click="currentfolder(item, index)" v-for="(item, index) in breadlist">
            <span style="cursor: pointer;"> {{ item.fileName }}</span>
        </el-breadcrumb-item>

    </el-breadcrumb>

</template>
<script setup>
import router from '@/router';
import service from '@/utils/Request';
import { ref } from 'vue';
import { useRoute } from 'vue-router';
const breadlist = ref([])
const emit = defineEmits(["getlist", "goback", "getall"])
const route = useRoute();
const back = () => {
    // let pathlist = route.query.path.split("/");
    // pathlist.splice(pathlist.length - 1, 1);
    breadlist.value.splice(breadlist.value.length - 1, 1);
    // router.push({
    //     path: "/index",
    //     query: {
    //         type: route.query.type,
    //         path: pathlist.join("/")
    //     }
    // })
    let fileId = breadlist.value.length > 0 ? breadlist.value[breadlist.value.length - 1].fileId : 0;
    emit("curfolder", fileId, breadlist.value)
}
const all = () => {
    // router.push({
    //     path: "/index",
    //     query: {
    //         type: route.query.type,

    //     }
    // })
    emit("getall")
}
const currentfolder = (item, index) => {
    breadlist.value.splice(index + 1, breadlist.value.length);
    // console.log(breadlist.value)
    // let path = [];
    emit("curfolder", breadlist.value[breadlist.value.length - 1].fileId, breadlist.value)


    // breadlist.value.forEach(el => {
    //     path.push(el.fileId)

    // })
    // router.push({
    //     path: "/index",
    //     query: {
    //         type: route.query.type,
    //         path: path.join("/")
    //     }
    // })
}
const getfolder = async () => {
    const res = await service.post("/file/getFolderInfo", {
        path: route.query.path
    });
    console.log(res)
    breadlist.value = res.data

}
const getfolder1 = async (path) => {
    const res = await service.post("/file/getFolderInfo", {
        path: path
    });
    console.log(res)
    breadlist.value = res.data

}
defineExpose({
    getfolder,
    getfolder1
})
</script>